Oddmuse Like Button

 

Seven months ago a link at the bottom of ZhurnalyWiki pages appeared which says "I like this!" When you click it, a line is appended to the page that reads "1 person liked this". If somebody else clicks it the count changes to "2 persons liked this", etc. How does it work? On 25 February 2011 I posted the naive question:

Alex, I'd like to have a Facebook-like "Like" button extension for Oddmuse to use in my ZhurnalyWiki journal — maybe just the word "Like" at the bottom of the page in the bar near "Edit this page" etc. — when somebody clicks on it, the number in front of it should increment. I could imagine various ways to try to implement this (by analogy with the Comment Count Extension perhaps?) — but instead of that maybe we should chat first about how it should look/work? Or do you already have a "Like" button and I just can't find it?! (^_^) Tnx Alex!

on the Oddmuse wiki page Like Button. Thanks to the magic of friendly collaboration, within a few days the associated page Comments on Like Button had a discussion, followed by a prototype implementation. That soon led to a module by Alex Schroeder and Ingo Belka that I tweaked and put into the Oddmuse directory here on zhurnaly.com:

# I LIKE! --- by Alex Schroeder & Ingo Belka
# trivial mods by Mark Zimmermann to make 'like' counts be <H4> aka ==== ... ====

$ModulesDescription .= '<p>$Id: like.pl,v 0.4z 2011/05/01 20:00:00 zhurnaly Exp $</p>';

$Action{like} = \&DoLike;
$LikeRegexp = qr'====(\d+) persons? liked this====';

sub DoLike {
  my $id = shift;
  my $crlf="\n";
  OpenPage(FreeToNormal($id));
  my $data = $Page{text};
  if ($data =~ /$LikeRegexp/mo) {
      my ($n) = $1;
      $n++;
      $data =~ s/$LikeRegexp/====$n persons liked this====/mo;
    } else {
      $data .= "$crlf====1 person liked this====$crlf";
    }
  SetParam('text', $data);
  SetParam('title', $OpenPageName);
  SetParam('oldtime', $Page{ts});
  SetParam('recent_edit', 'on');
  SetParam('summary', T('I like this!'));
  DoPost($id);
}

sub PrintMyContent {
  my $id = shift;
  print ScriptLink('action=like;id=' . UrlEncode($id), T('I like this!'), 'like')
    if $id and GetParam('action', 'browse') eq 'browse';
}

... and that's where the "I like this!" link comes from ...

^z - 2011-12-20

1 person liked this